/**
 * 
 */

package com.wutianyi.thrift.example.threads;

import org.apache.thrift.TProcessorFactory;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocolFactory;
import org.apache.thrift.server.TServer;
import org.apache.thrift.server.TThreadPoolServer;
import org.apache.thrift.server.TThreadPoolServer.Args;
import org.apache.thrift.transport.TServerSocket;
import org.apache.thrift.transport.TServerTransport;
import org.apache.thrift.transport.TTransportException;
import org.apache.thrift.transport.TTransportFactory;

import com.wutianyi.thrift.ThreadsTest;

/**
 * @author wutianyi
 * 
 */
public class ThreadServer {

	public static void main(String[] args) throws TTransportException {
		Thread thread = new Thread(new Runnable() {
			
			@Override
			public void run() {
		
				try {
					thread();
				}catch(TTransportException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
			}
		});
		thread.start();
	}

	private static void thread() throws TTransportException {

		TServerTransport transport = new TServerSocket(9090, 10000);

		// TTransportFactory transportFactory = new TTransportFactory();
		// TProtocolFactory protocolFactory = new TBinaryProtocol.Factory();

		ThreadsHandler handler = new ThreadsHandler(null);
		ThreadsTest.Processor processor = new ThreadsTest.Processor(handler);
		Args args1 =
				new Args(transport).processor(processor).minWorkerThreads(3).maxWorkerThreads(3);
		TServer server = new TThreadPoolServer(args1);
		handler.setServer(server);
		System.out.println("Thread Test service()!");
		server.serve();
	}
}
